package cos470_assignment1

import static org.junit.Assert.*
import org.junit.*

class BookIntgrationTests {

    @Before
    void setUp() {
        // Setup logic here
    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testBookCreation() {
       		
		def book = new Books(title: 'My First Book', author: 'Bradford Pare', description: 'This is my first book', minGradeLvl:2, maxGradeLvl:4, language:'English', category:'Reading skills')
		assertNotNull book.save()
		assertNotNull book.id

		def foundTitle = Books.get(book.id)
		assertEquals 'My First Book', foundTitle.title
    }
	
	void testBookUpdate() {
		
			def book = new Books(title: 'My First Book', author: 'Bradford Pare', description: 'This is my first book', minGradeLvl:2, maxGradeLvl:4, language:'English', category:'Reading skills')
			assertNotNull book.save()

			def foundTitle = Books.get(book.id)
			foundTitle.author = 'Parker Pare'
			foundTitle.save()
			
			def getChangedBook = Books.get(book.id)
			assertEquals 'Parker Pare', getChangedBook.author
	}
}
